package com.qingcheng.config;

import com.alibaba.fastjson.JSON;
import com.qingcheng.pojo.order.OrderItem;
import com.qingcheng.service.goods.StockBackService;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageListener;
import org.springframework.beans.factory.annotation.Autowired;

import java.io.UnsupportedEncodingException;
import java.util.List;

/**
 * @Author:boy
 * @Date:2019/7/21
 * @description:
 * @ModifiedBy:
 */

public class BackMessageConsumer implements MessageListener {
    @Autowired
    private StockBackService stockBackService;

    public void onMessage(Message message) {
        byte[] body = message.getBody();
        try {
            String s = new String(body, "utf-8");
            List<OrderItem> orderItems=JSON.parseObject(s, List.class);
            stockBackService.addList(orderItems);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
    }
}
